//
//  UIButton+Extension.swift
//  SwiftWB
//
//  Created by 钟清 on 17/3/25.
//  Copyright © 2017年 Zhong Qing. All rights reserved.
//

import UIKit

extension UIButton {
    convenience init(imageName: String?, backgroundImageName: String?) {
        // 属性初始化
        self.init()
        if let name = imageName {
            // 前景图片
            setImage(UIImage(named: name), forState: UIControlState.Normal)
            setImage(UIImage(named: name + "_highlighted"), forState: UIControlState.Selected)
        }
        if let backgroundName = backgroundImageName {
            // 后景图片
            setBackgroundImage(UIImage(named: backgroundName), forState: UIControlState.Normal)
            setBackgroundImage(UIImage(named: backgroundName + "_highlighted"), forState: UIControlState.Selected)
        }
        // 尺寸自适应
        sizeToFit()
    }
}
